<template>
	<view class="container">
		<cell-item v-if="appType === 'app-tch'|| appType === 'mp-tch'"  title="修改密码" @click="resetClick"></cell-item>
		<cell-item v-if="appType === 'app-tch'|| appType === 'mp-tch'"  title="忘记密码" @click="forgetClick"></cell-item>
		<cell-item v-if="appType === 'app-tch'|| appType === 'mp-tch'"  title="测评模式设置" @click="evaluateTypeClick"></cell-item>
		<cell-item v-if="channel !== 'xm'" title="关于我们" @click="aboutClick"></cell-item>
		<cell-item title="版本号" :desc="version" @click="versionClick"></cell-item>
		<u-button v-if="appType === 'app-tch'|| appType === 'mp-tch'" class="action" @click="exitClick">退出</u-button>
		<u-button v-else class="action" @click="userDebind">解绑</u-button>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import {
		userDebind
	} from '@/api/user.js'
	import CellItem from '../components/cell-item.vue'
	export default {
		components: {
			CellItem
		},
		data() {
			return {
				version: '',
				pkName: ''
			}
		},
		computed: {
			...mapState({
				appType: state => state.app.appType
			}),
			channel() {
				return getApp().globalData.channel;
			},
		},
		onLoad() {
			// #ifdef APP
				if(uni.getSystemInfoSync().platform === 'android'){
					var main = plus.android.runtimeMainActivity();
					var pkName = main.getPackageName();
					this.pkName = pkName
				}
				this.version = plus.runtime.version
				plus.runtime.getProperty(plus.runtime.appid, (info) => {
					console.log(info)
					//版本号
					this.version = `${plus.runtime.version}(${info.version})`;
				})
			// #endif

		},
		methods: {
			exitClick() {
				console.log('exitClick');
				this.$store.commit('user/logout');
				uni.reLaunch({
					url: '/pages/login',
					success() {
						
					},
					fail() {
						
					},
				})
			},
			
			userDebind() {
				// #ifdef APP-PLUS
					this.logout();
				// #endif
				
				// #ifdef H5
					if(process.env.NODE_ENV === 'development'){
						this.logout();
						return;
					}
					userDebind().then(res => {
						console.log(res);
						this.logout();
					})
				// #endif
				
				// #ifdef MP-WEIXIN*/
					if(process.env.NODE_ENV === 'development'){
						this.logout();
						return;
					}
					userDebind().then(res => {
						console.log(res);
						this.logout();
					})
				// #endif*/
			},
			
			logout() {
				this.$store.commit('user/logout');
				uni.reLaunch({
					url: '/pages/login',
					success() {
						
					},
					fail() {
						
					},
				})
			},
			
			resetClick() {
				this.$u.route({
					url: 'pages_base/common/reset-pwd-page'
				})
			},
			
			forgetClick() {
				this.$u.route({
					url: 'pages_base/common/forget-pwd-page'
				})
			},
			
			evaluateTypeClick() {
				this.$u.route({
					url: 'pages_base/common/setting-evaluate-type'
				})
			},
			
			aboutClick() {
				this.$u.route({
					url: 'pages_base/common/about'
				})
			},
			
			versionClick() {
				// #ifdef APP-PLUS
					if(uni.getSystemInfoSync().platform === 'android'){
						checkUpdate();
					}
				// #endif
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: $app-page-bg-color;
	}
	.container{
		display: flex;
		flex-direction: column;
		padding-left: 30rpx;
		padding-right: 30rpx;
		
		.action{
			margin-top: 60rpx;
			width: 100%;
		}
	}
	
</style>
